#include <LPC214x.H>                       /* LPC214x definitions */


#define BUZZER 		(1 << 25)
#define BUZZER_DIR 	IO1DIR
#define BUZZER_SET 	IO1SET
#define BUZZER_CLR 	IO1CLR
#define BUZZER_PIN	IO1PIN

#define BUZZER_ON	BUZZER_DIR 	|= BUZZER;	\
					BUZZER_CLR	|= BUZZER

#define BUZZER_OFF	BUZZER_DIR 	|= BUZZER;	\
					BUZZER_SET	|= BUZZER

#define BUZZER_STATE	((BUZZER_PIN & BUZZER) ? 0 : 1) 	

#define VIC_EXTI2_CH	(0x01 << 16)
#define VIC_EXTI1_CH	(0x01 << 15)



void delay(int count)
{
  int j=0,i=0;

  for(j=0;j<count;j++)
  {
    /* At 60Mhz, the below loop introduces
    delay of 10 us */
    for(i=0;i<35;i++);
  }
}

void ExtInt_ISR(void) 	__irq
{

	if(VICIRQStatus & VIC_EXTI1_CH )
 	{
 		BUZZER_ON;
		EXTINT |= 0x04;	   		/* ACK to peripheral block */
  	}
  	else if( VICIRQStatus & VIC_EXTI2_CH ) 
  	{
  		BUZZER_OFF;
		EXTINT |= 0x04;	   		/* ACK to peripheral block */
	}

	VICVectAddr = 0x00;		/* ACK to VIC Block */
}

int main (void) 
{
  
	PINSEL0 = 0x80000000 | 0x20000000;		 		/* Pin select to External INT2  */
	
  	VICDefVectAddr = (unsigned int)ExtInt_ISR;					 /* Assign ISR Handler address */
  	VICIntSelect &= (~(VIC_EXTI2_CH | VIC_EXTI1_CH));	/* This is optional to ensure the IRQ Mode */
	VICIntEnable = (VIC_EXTI2_CH | VIC_EXTI1_CH); 	  	/* Enabel the Interrupt for listening request */
	

   	BUZZER_ON;
   	delay(30000);
	BUZZER_OFF;
  	while (1){ 	 }
}
